package com.ygqh.baby.service.impl;
import java.util.List;
import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.AdminCustomAutoreply;
import  com.ygqh.baby.mapper.AdminCustomAutoreplyMapper;
import  com.ygqh.baby.service.AdminCustomAutoreplyService;
import  org.springframework.util.Assert;
import java.util.Arrays;
import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.AdminCustomAutoreplyExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class AdminCustomAutoreplyServiceImpl implements AdminCustomAutoreplyService{
	
	@Autowired
	private AdminCustomAutoreplyMapper adminCustomAutoreplyMapper;
	
	@Override
	public List<AdminCustomAutoreply> find() {
		AdminCustomAutoreplyExample example = new AdminCustomAutoreplyExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminCustomAutoreplyMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		AdminCustomAutoreplyExample example = new AdminCustomAutoreplyExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminCustomAutoreplyMapper.countByExample(example);
	}

	@Override
	public AdminCustomAutoreply findById(Long id) {
		return adminCustomAutoreplyMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(AdminCustomAutoreply adminCustomAutoreply) {
		return adminCustomAutoreplyMapper.insertSelective(adminCustomAutoreply);
	}

	@Override
	public int update(AdminCustomAutoreply adminCustomAutoreply) {
		return adminCustomAutoreplyMapper.updateByPrimaryKeySelective(adminCustomAutoreply);
	}

	@Override
	public ResultSet<AdminCustomAutoreply> search(QueryInfo queryInfo,String q) {
		List<AdminCustomAutoreply>  list =  adminCustomAutoreplyMapper.selectSuper(queryInfo, q);
		int count = adminCustomAutoreplyMapper.countSuper(q);
		ResultSet<AdminCustomAutoreply> resultSet = new ResultSet<AdminCustomAutoreply>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		AdminCustomAutoreplyExample example = new AdminCustomAutoreplyExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		AdminCustomAutoreply record = new AdminCustomAutoreply();
		record.setStatus(DataStatus.Delete);

		return adminCustomAutoreplyMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(AdminCustomAutoreply adminCustomAutoreply) {
		int r = 0;
		if(adminCustomAutoreply.getId() != null) {
			r = this.update(adminCustomAutoreply);
		}else {
			r = this.save(adminCustomAutoreply);
		}
		return r;
	}

}

